/*
 * Author: Sowmya Kameswaran
 */
package com.foo.CSVWriter;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class CSVWriterClient 
{
	CSVGenerationModuleRemote dataprovider = null;
	public CSVWriterClient()
	{
		try
		{
			Properties properties = new Properties();
			properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
			properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
			properties.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
			Context ctx = new InitialContext(properties);
			Object ref = ctx.lookup("CSVGenerationModule/remote");
			//DataProviderRemote 
			dataprovider = (CSVGenerationModuleRemote) PortableRemoteObject.narrow(ref, CSVGenerationModuleRemote.class);

		}
		catch(Exception e)
		{
			e.printStackTrace();
		}	
	}
	
	public void generateCSV(String filepath,String[] data, String type)
	{
		dataprovider.generateCsvFile(filepath,data,type);
		System.out.println("Sending data to server");
	}
}
